import request from '@/utils/request'
import type { ApiResponse } from '@/types'

// 根据API文档，这里应该是帖子功能，对应表白墙
export interface PostItem {
  postId: string
  title: string
  content: string
  userId: string
  createTimestamp: string
  updateTimestamp: string
  typeId: string
  visitNum: number
  subNum: number
  pic1?: string
  pic2?: string
  pic3?: string
  image?: string
  nickName?: string
  like?: number
  likeNum?: number
  commentNum?: number
}

export interface PostQuery {
  pageNo: number
  pageSize: number
  sortBy?: string
  isAsc?: boolean
  endKey?: string
  startTimestamp?: number
  typeId?: string
  str?: string
}

export interface PostDto {
  title: string
  content: string
  typeId: string
  pic1?: string
  pic2?: string
  pic3?: string
}

export const boardApi = {
  // 查询主页展示帖子 - POST /post/query
  getList: (params: PostQuery): Promise<ApiResponse<PostItem[]>> => {
    return request.post('/post/query', params)
  },

  // 获取单个帖子详情 - GET /post/getSinglePost/{postId}
  getDetail: (postId: string): Promise<ApiResponse<PostItem>> => {
    return request.get(`/post/getSinglePost/${postId}`)
  },

  // 发布帖子 - POST /post/insert
  add: (data: PostDto): Promise<ApiResponse<any>> => {
    return request.post('/post/insert', data)
  },

  // 更新帖子 - POST /post/update
  edit: (data: PostItem): Promise<ApiResponse<any>> => {
    return request.post('/post/update', data)
  },

  // 删除帖子 - DELETE /post/del/{postId}
  delete: (postId: string): Promise<ApiResponse<any>> => {
    return request.delete(`/post/del/${postId}`)
  },

  // 点赞帖子 - POST /post/like/{postId}
  like: (postId: string): Promise<ApiResponse<any>> => {
    return request.post(`/post/like/${postId}`)
  },

  // 取消点赞 - POST /post/dislike/{postId}
  dislike: (postId: string): Promise<ApiResponse<any>> => {
    return request.post(`/post/dislike/${postId}`)
  },

  // 访问帖子 - POST /post/visit/{postId}
  visit: (postId: string): Promise<ApiResponse<any>> => {
    return request.post(`/post/visit/${postId}`)
  },

  // 分页查询我的帖子 - GET /post/queryMyPost
  getMyPosts: (params: PostQuery): Promise<ApiResponse<any>> => {
    return request.get('/post/queryMyPost', { params })
  }
}